home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / SCRIPT.PAK / ED_BRIEF.SPP < prev    next >
Text File  |  1997-05-06  |  14KB  |  525 lines

  1. //----------------------------------------------------------------------------
  2. // cScript
  3. // (C) Copyright 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. // ED_BRIEF.SPP
  6. //    Script component of IDE's Editor Brief emulation.
  7. //    Provides support services for editing environment.
  8. //
  9. // $Revision:   1.16  $
  10. //
  11. //----------------------------------------------------------------------------
  12. // BRIEF Editor.
  13. //----------------------------------------------------------------------------
  14.  
  15. //----------------------------------------------------------------------------
  16. // Symbol Imports
  17. //----------------------------------------------------------------------------
  18.  
  19. import IDE;
  20. import editor;
  21. import scriptEngine;
  22. import bFileLoading;
  23. import bPopEditorKeyboard;
  24.  
  25. //
  26. // Mark this module as being a library module.
  27. //
  28. library;
  29.  
  30. //----------------------------------------------------------------------------
  31. // Symbol Defines
  32. //----------------------------------------------------------------------------
  33.  
  34. #define BOOKMARK_ID_SYSTEM_ONE   19
  35. #define BOOKMARK_ID_SYSTEM_TWO   18
  36. #define BOOKMARK_ID_SYSTEM_THREE 17
  37. #define FUNCTION_CONTINUE 0
  38. #define FUNCTION_END      1
  39.  
  40. //----------------------------------------------------------------------------
  41. // Menu Vectors.
  42. //----------------------------------------------------------------------------
  43.  
  44. DoIDEFileClose()      { return FUNCTION_CONTINUE; }
  45. DoIDEFileOpen()       { return FUNCTION_CONTINUE; }
  46. DoIDEFilePrint()      { if (!editor.BriefPrint()) return FUNCTION_CONTINUE; return FUNCTION_END; }
  47. DoIDEFileSave()       { if (!editor.Write()) return FUNCTION_CONTINUE; return FUNCTION_END; }
  48. DoIDEFileSaveAs()     { if (!editor.Write()) return FUNCTION_CONTINUE; return FUNCTION_END; }
  49. DoIDEFileSaveAll()    { return FUNCTION_CONTINUE; }
  50. DoIDEEditUndo()       { editor.Undo(); return FUNCTION_END; }
  51. DoIDEEditRedo()       { editor.Redo(); return FUNCTION_END; }
  52. DoIDEEditCut()        { editor.ModalCut(); return FUNCTION_END; }
  53. DoIDEEditCopy()       { editor.ModalCopy(); return FUNCTION_END; }
  54. DoIDEEditPaste()      { editor.Paste(); return FUNCTION_END; }
  55. DoIDEEditClear()      { editor.BriefDelete(); return FUNCTION_END; }
  56. DoIDEEditSelectAll()  { editor.SelectAll(); return FUNCTION_END; }
  57. DoIDEEditBufferList() { return FUNCTION_CONTINUE; }
  58. DoIDESearchFind()     { editor.BriefSetSearch(); return FUNCTION_CONTINUE; }
  59. DoIDESearchReplace(&b) { editor.BriefSetSearch(); b = true; return FUNCTION_CONTINUE; }
  60. DoIDESearchSearchAgain()  { return FUNCTION_CONTINUE; }
  61. DoIDESearchPreviousMessage() { IDE.ViewMessage("&Buildtime", true); return FUNCTION_CONTINUE; }
  62. DoIDESearchNextMessage()     { IDE.ViewMessage("&Buildtime", true); return FUNCTION_CONTINUE; }
  63.  
  64. //----------------------------------------------------------------------------
  65. // Methods.
  66. //----------------------------------------------------------------------------
  67.  
  68. //
  69. // Used to autoload the Brief Emulation specific Methods.
  70. //
  71. briefEmulation(bUnassign) {
  72.  
  73.    IDE.KeyboardManager.ScriptAbortKey = "<Escape>";
  74.    IDE.KeyboardManager.ProcessKeyboardAssignments(scriptEngine.StartupDirectory+IDE.KeyboardAssignmentFile,bUnassign);
  75.  
  76.    if (bUnassign) {
  77.       print "BRIEF emulation unloaded.";
  78.       scriptEngine.Unload(typeid(module()));
  79.    } else {
  80.       print "BRIEF emulation enabled.";
  81.    }
  82. }
  83.  
  84. //
  85. // Uses BRIEF specific behavior to determine backspace.
  86. //
  87. on editor:>BriefBackspace() {
  88.    declare ev = .TopView;
  89.    declare ep = ev.Position;
  90.  
  91.    if (ep.Column > 1) {
  92.        declare eb = .BlockExists();
  93.        if (eb) {
  94.           ep.Save();
  95.           ep.Move(eb.StartingRow,eb.StartingColumn);
  96.           ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
  97.           ep.Move(eb.EndingRow,eb.EndingColumn);
  98.           ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_TWO);
  99.           ep.Restore();
  100.           .BackspaceDelete(1);
  101.           ResetBlock();
  102.           ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  103.           BeginBlock();
  104.           ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_TWO);
  105.           EndBlock();
  106.        }
  107.     else
  108.        .BackspaceDelete(1);
  109.    }
  110. }
  111.  
  112. //
  113. // Uses BRIEF specific behavior to determine indenting position.
  114. //
  115. on editor:>BriefDelete() {
  116.    declare eb = .BlockExists();
  117.  
  118.    if (eb != NULL) {
  119.       if (eb.Size != 0) {
  120.  
  121.           declare ep = .TopView.Position;
  122.                          declare nRestoreColumn = 0;
  123.  
  124.                          if (eb.Style == LINE_BLOCK) {
  125.                                   nRestoreColumn = ep.Column;
  126.                          }
  127.  
  128.                          RemoveBlock(eb,TRUE);
  129.  
  130.                          if (nRestoreColumn)
  131.                                   ep.Move(0,nRestoreColumn);
  132.  
  133.           IDE.StatusBar = "Block deleted";
  134.           return;
  135.          }
  136.    }
  137.    return .DeleteChar(1);
  138. }
  139.  
  140. //
  141. // Uses BRIEF specific behavior to determine indenting position.
  142. //
  143. on editor:>BriefDeleteWord(declare nLeft) {
  144.  
  145.         declare bBlock = FALSE;
  146.         declare ev = .TopView;
  147.         declare ep = ev.Position;
  148.         declare eb = .BlockExists();
  149.  
  150.         if (eb != NULL) {
  151.                  bBlock = TRUE;
  152.                  eb.Save();
  153.         } else
  154.                  eb = ev.Block;
  155.  
  156.         ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
  157.  
  158.         if (initialized(nLeft)) {
  159.                  BeginBlock(EXCLUSIVE_BLOCK);
  160.                  .BriefBackwardWord();
  161.                  eb.Delete();
  162.         } else {
  163.                  BeginBlock(EXCLUSIVE_BLOCK);
  164.  
  165.        declare bStartedAtEnd = (ep.Character == 13);
  166.  
  167.        if (ep.IsWordCharacter)
  168.           ep.MoveCursor(SKIP_RIGHT | SKIP_WORD);
  169.        else if (ep.IsSpecialCharacter)
  170.           ep.MoveCursor(SKIP_RIGHT | SKIP_SPECIAL);
  171.  
  172.        if (bStartedAtEnd)
  173.          ep.MoveCursor(SKIP_RIGHT | SKIP_WHITE | SKIP_STREAM);
  174.        else
  175.          ep.MoveCursor(SKIP_RIGHT | SKIP_WHITE);
  176.  
  177.        EndBlock();
  178.        eb.Delete();
  179.         }
  180.  
  181.         ResetBlock();
  182.         ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  183.  
  184.         if (bBlock == TRUE) {
  185.                  eb.Restore();
  186.         }
  187. }
  188.  
  189. on editor:>BriefForwardWord() {
  190.  
  191.    declare eb = .BlockExists();
  192.    declare ep = .TopView.Position;
  193.  
  194.    if (eb != NULL) {
  195.        eb.Save();
  196.        ep.Save();
  197.    }
  198.  
  199.    if (ep.IsWordCharacter)
  200.       ep.MoveCursor(SKIP_RIGHT | SKIP_WORD);
  201.    else if (ep.IsSpecialCharacter)
  202.       ep.MoveCursor(SKIP_RIGHT | SKIP_SPECIAL);
  203.  
  204.    ep.MoveCursor(SKIP_RIGHT | SKIP_WHITE | SKIP_STREAM);
  205.  
  206.    if (eb != NULL) {
  207.        declare nRow = ep.Row;
  208.        declare nColumn = ep.Column;
  209.        ep.Restore();
  210.        eb.Restore();
  211.        eb.Extend(nRow, nColumn);
  212.    }
  213. }
  214.  
  215.  
  216. on editor:>BriefBackwardWord() {
  217.  
  218.    declare eb = .BlockExists();
  219.         declare ep = .TopView.Position;
  220.  
  221.    if (eb != NULL) {
  222.        eb.Save();
  223.        ep.Save();
  224.    }
  225.  
  226.    ep.MoveCursor(SKIP_LEFT | SKIP_WHITE | SKIP_STREAM);
  227.  
  228.    declare nColumn = ep.Column;
  229.  
  230.    ep.MoveCursor(SKIP_LEFT | SKIP_SPECIAL);
  231.  
  232.    if (nColumn == ep.Column)
  233.        ep.MoveCursor(SKIP_LEFT | SKIP_WORD);
  234.  
  235.         if (eb != NULL) {
  236.                  declare nRow = ep.Row;
  237.                  declare nColumn = ep.Column;
  238.                  ep.Restore();
  239.                  eb.Restore();
  240.                  eb.Extend(nRow,nColumn);
  241.         }
  242. }
  243.  
  244. //
  245. // Split line at current cursor location and continue editing.
  246. //
  247. on editor:>BriefOpenLine() {
  248.    .ModalMoveEOL();
  249.    .TopView.Position.InsertCharacter('\r');
  250. }
  251.  
  252. //
  253. // Uses BRIEF specific behaviour to open a new file for editing.
  254. //
  255. on editor:>BriefEditFile() {
  256.  
  257.         declare sFileName = new 
  258.          String(ContextSensitiveFileDialog("EditFile", "File:", "*.*"));
  259.  
  260.         if (sFileName.Text != "" && IDE.IsLegalFileName(sFileName.Text)) {
  261.  
  262.             declare eb = new EditBuffer(sFileName.Text);
  263.  
  264.             if (eb == NULL || eb.IsValid == FALSE) {
  265.                 IDE.ReportError("Unable to create new edit buffer");
  266.                 return;
  267.             }
  268.  
  269.             if (initialized(.TopView)) {
  270.                 declare ev = .TopView;
  271.                 if (ev != NULL && ev.IsValid == TRUE)
  272.                 ev.Attach(eb); // replace the existing view
  273.             } else {
  274.                 declare EditWindow ew(eb); // create a new Editor Window
  275.                 ew.Activate();             // and activate it...
  276.             }
  277.         }
  278. }
  279.  
  280. //
  281. // Uses BRIEF specific behaviour to print.
  282. //
  283. on editor:>BriefPrint() {
  284.    declare eb = .BlockExists();
  285.  
  286.    if (eb != NULL) {
  287.       eb.Print();
  288.       return true;
  289.    }
  290.  
  291.    IDE.StatusBar = "No marked block.";
  292.    return false;
  293. }
  294.  
  295. //
  296. // Repeat the last search/replace operation.
  297. //
  298. on editor:>BriefReplaceAgain() {
  299.  
  300.    declare eb = .BlockExists();
  301.         declare ep = .TopView.Position;
  302.  
  303.    ep.Save();
  304.    if (eb != NULL)
  305.       eb.Save();
  306.    ep.SearchOptions.Copy(.SearchOptions);
  307.    ep.ReplaceAgain();
  308.    ep.Restore();
  309.    if (eb != NULL)
  310.       eb.Restore();
  311. }
  312.  
  313. //
  314. // Uses BRIEF specific behavior to determine indenting position.
  315. //
  316. declare gbBriefSSBypass = false;
  317.  
  318. on editor:>BriefSetSearch() {
  319.  
  320.    if (!gbBriefSSBypass) {
  321.       .SearchOptions.GoForward = true;
  322.    }
  323.  
  324.    gbBriefSSBypass = false;
  325. }
  326.  
  327. on editor:>BriefSearch(declare bReplace) {
  328.  
  329.    declare km = IDE.KeyboardManager;
  330.    declare key = km.CodeToKey(km.LastKeyProcessed);
  331.  
  332.    if (key == "<Alt-F5>" || key == "<Alt-F6>" ) {
  333.        .SearchOptions.GoForward = false;
  334.        gbBriefSSBypass = true;
  335.    }
  336.  
  337.  if (bReplace) {
  338.     declare eb = .BlockExists();
  339.          declare ep = .TopView.Position;
  340.  
  341.          ep.Save();
  342.     if (eb != NULL)
  343.        eb.Save();
  344.     IDE.SearchReplace();
  345.          ep.Restore();
  346.     if (eb != NULL)
  347.        eb.Restore();
  348.  
  349.  } else
  350.     IDE.SearchFind();
  351. }
  352.  
  353. //
  354. // Uses BRIEF specific behavior to determine indenting position.
  355. //
  356. on editor:>BriefSmartTab() {
  357.  
  358.    declare eb = .BlockExists();
  359.    if (eb != NULL) {
  360.       eb.Indent(.Options.BlockIndent);
  361.    } else if (.Options.BufferOptions.InsertMode)
  362.       .TopView.Position.InsertCharacter('\t');
  363.    else
  364.       .TopView.Position.Tab(1);
  365. }
  366.  
  367. //
  368. // Uses BRIEF specific behavior to determine outdenting position.
  369. //
  370. on editor:>BriefSmartBackTab() {
  371.    declare eb = .BlockExists();
  372.    if (eb != NULL) {
  373.       eb.Indent(-(.Options.BlockIndent));
  374.    } else
  375.       .TopView.Position.Tab(-1);
  376. }
  377.  
  378. //
  379. // Copy currently selected block, switch to single line block mode if
  380. // needed.
  381. //
  382. on editor:>ModalCopy(declare append) {
  383.    declare eb = .BlockExists();
  384.    declare msg;
  385.    if (eb == NULL) {
  386.       eb = ToggleBlockStyle(LINE_BLOCK);
  387.       msg = "Line copied to scrap";
  388.    } else
  389.       msg = "Block copied to scrap";
  390.  
  391.    CopyBlock(eb,append);
  392.  
  393.    IDE.StatusBar = msg;
  394. }
  395.  
  396. //
  397. // Cut currently selected block, switch to single line block mode if
  398. // needed.
  399. //
  400. on editor:>ModalCut() {
  401.    // declare variables.
  402.    declare eb = .BlockExists();
  403.    declare ep = .TopView.Position;
  404.    declare nRestoreColumn = 0;
  405.    declare msg = "Block deleted to scrap";
  406.  
  407.    if (eb == NULL) {
  408.       nRestoreColumn = ep.Column;
  409.       eb = ToggleBlockStyle(LINE_BLOCK);
  410.       msg = "Line cut to scrap";
  411.    }
  412.  
  413.    RemoveBlock(eb);
  414.  
  415.    if (nRestoreColumn)
  416.        ep.Move(0,nRestoreColumn);
  417.  
  418.    IDE.StatusBar = msg;
  419. }
  420.  
  421. //
  422. // Uses BRIEF specific behavior to determine next end key position.
  423. //
  424. declare __LastEndKeysProcessed;
  425. declare __LastEndKeysProcessedStep;
  426.  
  427. on editor:>ModalEnd() {
  428.  
  429.    declare keyCnt = IDE.KeyboardManager.KeysProcessed;
  430.  
  431.    if (__LastEndKeysProcessed + 1 == keyCnt){// We are still in the sequence.
  432.       __LastEndKeysProcessed++;
  433.       __LastEndKeysProcessedStep++;
  434.    } else {                                 // Something else was pressed.
  435.       __LastEndKeysProcessed=keyCnt;
  436.       __LastEndKeysProcessedStep=1;
  437.    }
  438.  
  439.    switch(__LastEndKeysProcessedStep) {
  440.    case 1:
  441.       .ModalMoveEOL();
  442.       break;
  443.    case 2:
  444.       .ModalMoveViewBottom();
  445.       break;
  446.    case 3:
  447.       .ModalMoveEOF();
  448.       break;
  449.    }
  450. }
  451.  
  452. //
  453. // Uses BRIEF specific behavior to determine next home key position.
  454. //
  455. declare __LastHomeKeysProcessed;
  456. declare __LastHomeKeysProcessedStep;
  457.  
  458. on editor:>ModalHome() {
  459.    declare keyCnt = IDE.KeyboardManager.KeysProcessed;
  460.  
  461.    if (__LastHomeKeysProcessed + 1 == keyCnt){// We are still in the sequence.
  462.       __LastHomeKeysProcessed++;
  463.       __LastHomeKeysProcessedStep++;
  464.    } else {                                 // Something else was pressed.
  465.       __LastHomeKeysProcessed=keyCnt;
  466.       __LastHomeKeysProcessedStep=1;
  467.    }
  468.  
  469.    switch(__LastHomeKeysProcessedStep) {
  470.    case 1:
  471.       .ModalMoveBOL();
  472.       break;
  473.    case 2:
  474.       .ModalMoveViewTop();
  475.       break;
  476.    case 3:
  477.       .ModalMoveBOF();
  478.       break;
  479.    }
  480. }
  481.  
  482. //
  483. // Get the direction key for new view.
  484. //
  485.  
  486. declare kbdCreateView = NULL;
  487.  
  488. on editor:>BriefCreateView() {
  489.    if (kbdCreateView == NULL) {
  490.       kbdCreateView = new Keyboard(FALSE);
  491.                 kbdCreateView.Assign("<Left>","editor.BriefCreateViewSelect(LEFT);",ASSIGN_IMPLICIT_KEYPAD);
  492.                 kbdCreateView.Assign("<Right>","editor.BriefCreateViewSelect(RIGHT);",ASSIGN_IMPLICIT_KEYPAD);
  493.                 kbdCreateView.Assign("<Up>","editor.BriefCreateViewSelect(UP);",ASSIGN_IMPLICIT_KEYPAD);
  494.                 kbdCreateView.Assign("<Down>","editor.BriefCreateViewSelect(DOWN);",ASSIGN_IMPLICIT_KEYPAD);
  495.                 kbdCreateView.Assign("<Escape>","editor.BriefCreateViewSelect();");
  496.       kbdCreateView.DefaultAssignment = ";";
  497.    }
  498.  
  499.    IDE.KeyboardManager.Push(kbdCreateView, "Editor", FALSE);
  500.    bPopEditorKeyboard = true;
  501.    IDE.StatusBar = "Select side for new view (use cursor keys).";
  502. }
  503.  
  504. on editor:>BriefCreateViewSelect(declare direction) {
  505.  
  506.    if (initialized(direction)) {
  507.       editor.CreateView(direction);
  508.       IDE.StatusBar = "";
  509.    } else
  510.       IDE.StatusBar = "Command cancelled.";
  511.  
  512.    IDE.KeyboardManager.Pop("Editor");
  513.    bPopEditorKeyboard = false;
  514. }
  515.  
  516. on editor:>BriefZoomPaneToggle() {
  517.    if (initialized(.TopView)) {
  518.        if (.TopView.IsZoomed)
  519.            .TopView.IsZoomed = false;
  520.        else
  521.            .TopView.IsZoomed = true;
  522.    }
  523.  
  524. }
  525.